"""
Web
"""

import streamlit as st
from src.web.components.header import Header
from src.web.components.result_display import ResultDisplay

class ResultPage:
    """"""
    
    def __init__(self):
        self.result_display = ResultDisplay()
    
    def render(self):
        """"""
        # 
        Header.render()
        
        # 
        if 'result' not in st.session_state or not st.session_state.result:
            st.error(" ")
            if st.button(" "):
                st.session_state.current_page = 'main'
                st.rerun()
            return
        
        # 
        result_data = st.session_state.result
        settings = result_data.get('settings', {})
        
        # 
        self.result_display.render(result_data, settings)
        
        # 
        st.markdown("---")
        
        col1, col2, col3 = st.columns(3)
        
        with col1:
            if st.button(" ", type="primary", use_container_width=True):
                self._cleanup_session_state()
                st.session_state.current_page = 'upload'
                st.rerun()
        
        with col2:
            if st.button(" ", use_container_width=True):
                st.session_state.current_page = 'settings'
                st.rerun()
        
        with col3:
            if st.button(" ", use_container_width=True):
                st.session_state.current_page = 'main'
                st.rerun()
    
    def _cleanup_session_state(self):
        """session state"""
        keys_to_remove = [
            'processing', 'processing_complete', 'processing_error',
            'progress_value', 'progress_message', 'uploaded_file_path',
            'video_info', 'result'
        ]
        
        for key in keys_to_remove:
            if key in st.session_state:
                del st.session_state[key]